﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Yugi.Client.Control
{
	/// <summary>
	/// Interaction logic for YDeck.xaml
	/// </summary>
	public partial class YDeck : UserControl , IInvoke
	{
        PlayerModel model;
		public YDeck()
		{
			this.InitializeComponent();
            this.DataContextChanged += new DependencyPropertyChangedEventHandler(YDeck_DataContextChanged);
		}

        void YDeck_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (!(e.NewValue is PlayerModel)) return;
            model = (PlayerModel)e.NewValue;
            if (model == null)
                return;
            model.Deck_Presenter = this;
        }

		private void UserControl_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
		{
			VisualStateManager.GoToState(this,"Mouseover",true);
		}

		private void UserControl_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
		{
			VisualStateManager.GoToState(this,"Default",true);
		}

        public int Number 
        {
            get
            {
                return Convert.ToInt32( txt_number.Text);
            }
            set
            {
                txt_number.Text = value.ToString();
            }
        }
        #region IInvoke Members

        public void Do(ClientMSG msg, params object[] obj)
        {
            switch (msg)
            {
                case ClientMSG.Api_DrawCard:
                    this.Number--;
                    break;
                case ClientMSG.RutBai:
                    this.Number--;
                    break;
                case ClientMSG.ThemBaiDoiThuTay:
                    this.Number--;
                    break;
                case ClientMSG.Reset:
                    Reset();
                    break;
            }
        }
        public void Refresh()
        {
            
        }
        #endregion
        public void Reset()
        {
            this.Number = 40;
            this.model.Reset();
        }
    }
}